package com.haiya.ocp;

/**
 * @author qiaoguoqiang
 */
public class OpenClosed {
    public static void main(String[] args) {
        // 使用看看存在的问题
        GraphicEditor graphicEditor = new GraphicEditor();

        graphicEditor.drawShape(new Rectangle());

        graphicEditor.drawShape(new Circle());

        graphicEditor.drawShape(new Triangle());
    }
}

/**
 * 用于绘图的类
 */
class GraphicEditor {
    /**
     * 接收不同的图形来画图
     * @param s
     */
    public void drawShape(Shape s) {
        if (s.type == 1) {
            drawRectangle(s);
        } else if (s.type == 2) {
            drawCycle(s);
        } else if (s.type == 3) {
            drawTriangle(s);
        }
    }

    public void drawRectangle(Shape s) {
        System.out.println("矩形");
    }

    public void drawCycle(Shape s) {
        System.out.println("圆形");
    }
    public void drawTriangle(Shape s) {
        System.out.println("三角形");
    }
}

class Shape {
    int type;
}

class Rectangle extends Shape {
    public Rectangle() {
        super.type = 1;
    }
}

class Circle extends Shape {
    public Circle() {
        super.type = 2;
    }
}

class Triangle extends Shape {
    public Triangle() {
        super.type = 3;
    }
}